package nz.ac.massey.doi_information_extractor.gui;


import javax.swing.JProgressBar;

public class ProgressbarUpdater extends Thread {

	JProgressBar progressBar;
	int counter;
	boolean processing;

	public ProgressbarUpdater(JProgressBar progressBar) {
		this.progressBar = progressBar;
		progressBar.setMinimum(0);
		progressBar.setMaximum(500);
		counter = 0;
		processing = true;
	}

	public void run() {
		while (processing) {
			if (counter <= 500)
				progressBar.setValue(counter);
			else {
				counter = 0;
				progressBar.setValue(counter);
			}
			counter++;
			progressBar.update(progressBar.getGraphics());
			try {
				sleep(20);
			} catch (InterruptedException e) {
				processing = false;
				progressBar.setValue(0);
				break;
			}
		}
		progressBar.setValue(0);
	}

	public void stopUpdater(){
		processing = false;
		progressBar.setValue(0);
	}
}
